import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CupertinoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoApp(
      title: '苹果风格',
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  double _value = 25.0;
  bool _isOpen = false;

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        middle: Text("Cupertino Demo"),
        leading: Icon(CupertinoIcons.back),
        trailing: Icon(CupertinoIcons.share),
      ),
      child: SafeArea(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              CupertinoActivityIndicator(),
              CupertinoSlider(
                value: _value,
                min: 0.0,
                max: 100.0,
                onChanged: (double value) {
                  setState(() {
                    _value = value;
                  });
                },
              ),
              CupertinoSwitch(
                  value: _isOpen,
                  onChanged: (value) {
                    setState(() {
                      _isOpen = !_isOpen;
                    });
                  }),

              CupertinoButton(
                color: CupertinoColors.activeBlue,
                child: Text('苹果风格按钮'),
                onPressed: () {
                  showCupertinoDialog(
                    context: context,
                    builder: (_) {
                      return CupertinoAlertDialog(
                        title: Text("这里是标题"),
                        content: Text("内容内容内容内容内容内容内容内容内容内容内容"),
                        actions: <Widget>[
                          CupertinoDialogAction(
                            onPressed: () {
                              Navigator.pop(_);
                            },
                            child: Text("确认"),
                          ),
                          CupertinoDialogAction(
                            onPressed: () {
                              Navigator.pop(_);
                            },
                            child: new Text("取消"),
                          ),
                        ],
                      );
                    },
                  );
                },
              ),
              CupertinoTabBar(items: [
                BottomNavigationBarItem(icon: Icon(CupertinoIcons.home)),
                BottomNavigationBarItem(icon: Icon(CupertinoIcons.time)),
                BottomNavigationBarItem(icon: Icon(CupertinoIcons.shopping_cart)),
              ]),
            ],
          ),
        ),
      ),
    );
  }
}
